import 'package:flutter/material.dart';
import 'package:news_demo/View/NewValue/NewValue.dart';

import '../../AttentionHomeIndex/ItmeIndex.dart';

class Follow extends StatefulWidget {
  const Follow({Key? key}) : super(key: key);

  @override
  State<Follow> createState() => _IndexState();
}

class _IndexState extends State<Follow> {

  late List<Widget> PersionList;
  late List<Widget> NewsList;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    PersionList=[
      PersionItme(),
      PersionItme(),
      PersionItme(),
      PersionItme(),
      PersionItme(),
      PersionItme(),
      PersionItme(),
      PersionItme(),
    ];

    NewsList=[
      NewsItme(),
      NewsItme(),
      NewsItme(),
    ];

  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      scrollDirection: Axis.vertical,
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.fromLTRB(8, 0, 0, 0),
            height: 26,
            width: double.infinity,
            alignment: Alignment.centerLeft,
            child: Text("关注更新"),
          ),
          Divider(
            height: 4,
            color: Colors.black45,
          ),
          SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Row(
              children: PersionList,
            ),
          ),
          Container(
            width: double.infinity,
            height: 6,
            color: Colors.black45,
          ),
          Container(
            padding: EdgeInsets.fromLTRB(8, 0, 0, 0),
            height: 26,
            width: double.infinity,
            alignment: Alignment.centerLeft,
            child: Text("关注动态"),
          ),
          Divider(
            height: 4,
            color: Colors.black45,
          ),
          ...NewsList
        ],
      ),
    );
  }
}

class PersionItme extends StatelessWidget {
  const PersionItme({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 70,
      height: 70,
      margin: EdgeInsets.all(8),
      child: GestureDetector(
        onTap: (){
          Navigator.push(context, MaterialPageRoute(builder: (context)=>ItmeIndex(keys: "0",)));
        },
        child:Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Container(
              width: 40,
              height: 40,
              child: Image.network("https://img0.baidu.com/it/u=1379004532,2711909750&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"),
            ),
            Text("某某新闻")
          ],
        ),
      )
    );
  }
}

class NewsItme extends StatelessWidget {
  const NewsItme({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(2, 0, 2, 0),
      width: double.infinity,
      child: Column(
        children: [
          ListTile(
            leading: GestureDetector(
              child: Image.network("https://img0.baidu.com/it/u=1379004532,2711909750&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"),
              onTap: (){
                Navigator.push(context, MaterialPageRoute(builder: (context)=>ItmeIndex(keys: "0",)));
              },
            ),
            title: Text("某某新闻"),
            subtitle: Text("2023/1/5 10:00"),
            trailing: GestureDetector(
              child: Icon(Icons.drag_indicator,size: 36,),
              onTap: (){

              },
            ),
          ),
          GestureDetector(
            onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (context)=>NewValue(NewKey: "1")));
            },
            child:Container(
                alignment: Alignment.center,
                padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
                child: Column(
                  children: [
                    Text(
                      "许家印：今年是关键年，恒大一定能偿还各种债务、化解风险，一定能涅槃重生。",
                      style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(0, 4, 0, 20),
                      width: double.infinity,
                      child: Image.network("http://n.sinaimg.cn/default/1_img/upload/3933d981/674/w899h575/20210130/b066-kiksqxh1091087.jpg"),
                    ),
                    Divider(
                      height: 0,
                      color: Colors.black45,)
                  ],
                )
            ),
          ),
        ],
      ),
    );
  }
}

